home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / trace / tcpdump-2.2.1 / tcplex.l < prev    next >
Encoding:
Lex Description  |  1992-02-14  |  3.5 KB  |  147 lines

  1. %{
  2. /*
  3.  * Copyright (c) 1988-1990 The Regents of the University of California.
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that: (1) source code distributions
  8.  * retain the above copyright notice and this paragraph in its entirety, (2)
  9.  * distributions including binary code include the above copyright notice and
  10.  * this paragraph in its entirety in the documentation or other materials
  11.  * provided with the distribution, and (3) all advertising materials mentioning
  12.  * features or use of this software display the following acknowledgement:
  13.  * ``This product includes software developed by the University of California,
  14.  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  15.  * the University nor the names of its contributors may be used to endorse
  16.  * or promote products derived from this software without specific prior
  17.  * written permission.
  18.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  19.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  20.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21.  */
  22.  
  23. #ifndef lint
  24. static char rcsid[] =
  25.     "@(#) $Header: tcplex.l,v 1.26 92/02/14 15:16:35 mccanne Exp $ (LBL)";
  26. #endif
  27.  
  28. /*
  29.  * Compiling with gcc under SunOS will cause problems unless we have this
  30.  * cruft here.  The flex skeleton includes stddef.h which defines these types
  31.  * (under gcc).  They will conflict with Sun's definitions in sys/types.h.
  32.  */
  33. #define size_t xxxsize_t
  34. #define ptrdiff_t xxxptrdiff_t
  35. #define wchar_t xxxwchar_t
  36. #include <sys/types.h>
  37. #undef size_t
  38. #undef ptrdiff_t
  39. #undef wchar_t
  40.  
  41. #include "nametoaddr.h"
  42.  
  43. /*
  44.  * We need bpf since enum bpf_code is in YYSTYPE.
  45.  */
  46. #include <sys/time.h>
  47. #include <net/bpf.h>
  48.  
  49. #include "gencode.h"
  50. #include "tokdefs.h"
  51.  
  52. #ifdef FLEX_SCANNER
  53. #undef YY_INPUT
  54. #define YY_INPUT(buf, result, max)\
  55.  {\
  56.     char *src = in_buffer;\
  57.     int i;\
  58. \
  59.     if (*src == 0)\
  60.         result = YY_NULL;\
  61.     else {\
  62.         for (i = 0; *src && i < max; ++i)\
  63.             buf[i] = *src++;\
  64.         in_buffer += i;\
  65.         result = i;\
  66.     }\
  67.  }
  68. #else
  69. #undef getc
  70. #define getc(fp)  (*in_buffer == 0 ? EOF : *in_buffer++)
  71. #endif
  72.  
  73. extern YYSTYPE yylval;
  74. static char *in_buffer;
  75.  
  76. %}
  77.  
  78. N        ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
  79. B        ([0-9A-Fa-f][0-9A-Fa-f]?)
  80.  
  81. %a 3000
  82.  
  83. %%
  84. dst        return DST;
  85. src        return SRC;
  86.  
  87. link|ether|ppp|slip  return LINK;
  88. arp        return ARP;
  89. rarp        return RARP;
  90. ip        return IP;
  91. tcp        return TCP;
  92. udp        return UDP;
  93. icmp        return ICMP;
  94.  
  95. host        return HOST;
  96. net        return NET;
  97. port        return PORT;
  98. proto        return PROTO;
  99.  
  100. gateway        return GATEWAY;
  101.  
  102. less        return LESS;
  103. greater        return GREATER;
  104. byte        return BYTE;
  105. broadcast    return TK_BROADCAST;
  106. multicast    return TK_MULTICAST;
  107.  
  108. and        return AND;
  109. or        return OR;
  110. not        return '!';
  111.  
  112. len        return LEN;
  113.  
  114. [ \n\t]            ;
  115. [+\-*/:\[\]!<>()&|=]    return yytext[0];
  116. ">="            return GEQ;
  117. "<="            return LEQ;
  118. "!="            return NEQ;
  119. "=="            return '=';
  120. "<<"            return LSH;
  121. ">>"            return RSH;
  122. {N}            { yylval.i = stoi(yytext); return NUM; }
  123. ({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N})    { 
  124.             yylval.h = atoin(yytext); return HID;
  125. }
  126. {B}:{B}:{B}:{B}:{B}:{B} { yylval.e = ETHER_aton(yytext); return EID; }
  127. {B}:+({B}:+)+        { error("bogus ethernet address %s", yytext); }
  128. [A-Za-z][-_.A-Za-z0-9]*    { yylval.s = yytext; return ID; }
  129. "\\"[^ !()\n\t]+    { yylval.s = yytext + 1; return ID; }
  130. [^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+    { error("illegal token: %s\n", yytext); }
  131. .            { error("illegal char '%c'", *yytext); }
  132. %%
  133. void
  134. lex_init(buf)
  135.     char *buf;
  136. {
  137.     in_buffer = buf;
  138. }
  139. #ifndef FLEX_SCANNER
  140. int 
  141. yywrap()
  142. /* so we don't need -ll */
  143. {
  144.     return 1;
  145. }                
  146. #endif
  147.